package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingLevelDto;
import com.zzyl.service.NursingLevelService;
import com.zzyl.vo.NursingLevelVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static com.zzyl.base.ResponseResult.success;

@RestController
@RequestMapping("/nursingLevel")
@Api(tags = "护理等级管理")
public class NursingLevelController {

    @Autowired
    private NursingLevelService nursingLevelService;

    /**
     * 护理等级分页查询
     * @return
     */
    @GetMapping("/listByPage")
    @ApiOperation(value = "护理等级分页查询")
    public ResponseResult<PageResponse<NursingLevelVo>> listByPage(
            @ApiParam(value = "护理等级名称") String name,
            @ApiParam(value = "页码") @RequestParam(defaultValue = "1") Integer pageNum,
            @ApiParam(value = "每页页数") @RequestParam(defaultValue = "10") Integer pageSize,
            @ApiParam(value = "护理等级状态") Integer status){
            PageResponse<NursingLevelVo> pageResponse = nursingLevelService.listByPage(name,pageNum,pageSize,status);
            return success(pageResponse);
    }

    /**
     * 添加护理等级
     * @param nursingLevelDto
     * @return
     */
    @PostMapping("/insert")
    @ApiOperation(value = "添加护理等级")
    public ResponseResult insert(@RequestBody NursingLevelDto nursingLevelDto){
        nursingLevelService.insert(nursingLevelDto);
        return success();
    }

    /**
     * 根据id查询护理等级
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    @ApiOperation(value = "根据id查询护理等级")
    public ResponseResult<NursingLevelVo> getById(@PathVariable Long id){
        NursingLevelVo nursingLevelVo = nursingLevelService.getById(id);
        return success(nursingLevelVo);
    }

    /**
     * 修改护理等级
     * @param nursingLevelDto
     * @return
     */
    @PutMapping("/update")
    @ApiOperation(value = "修改护理等级")
    public ResponseResult update(@RequestBody NursingLevelDto nursingLevelDto){
        nursingLevelService.update(nursingLevelDto);
        return success();
    }

    /**
     * 删除护理等级
     * @param id
     * @return
     */
    @DeleteMapping("/delete/{id}")
    @ApiOperation(value = "删除护理等级")
    public ResponseResult delete(@PathVariable Long id){
        nursingLevelService.delete(id);
        return success();
    }

    /**
     * 修改护理等级状态
     * @param id
     * @param status
     * @return
     */
    @PutMapping("/{id}/status/{status}")
    @ApiOperation(value = "修改护理等级状态")
    public ResponseResult updateStatus(@PathVariable Long id,@PathVariable Integer status){
        nursingLevelService.updateStatus(id,status);
        return success();
    }

    /**
     * 查询所有护理等级
     * @return
     */
    @GetMapping("/listAll")
    @ApiOperation(value = "查询所有护理等级")
    public ResponseResult<List<NursingLevelVo>> listAll(){
        List<NursingLevelVo> nursingLevelVos = nursingLevelService.listAll();
        return success(nursingLevelVos);
    }
}
